<?php
/**
 */
class PhotosTable extends Doctrine_Table
{
    public function addAlbumPhotos($album_id,$filenames,$org_type,$memid)
	{
	    $photo = new Photos();
		$photo ->addedby = $memid;
		$photo ->photo = trim($filenames);
		$photo ->type = $org_type;
		$photo ->added_date = date('Y-m-d H:i:s');
		$photo ->photo_status = 1;
		$photo ->album_id = $album_id;
		//$user ->created_by = $createdBy;
		$photo ->save();
		return $photo->photo_id;
		
	}
	public function deletePhotoByPhotoId($photo_id)
	{
		 $query = new Doctrine_Query();
		$query->update('Photos p')
			  ->set('p.photo_status',"'0'")
			  ->where("p.photo_id='".$photo_id."'");
		  //echo $query->getSqlQuery();exit;
		return $query->execute();
	}
	public function addPhoto($memid,$org_type,$album_id,$photos,$diffId,$comments_allow)
	{
			//echo $photo;exit;
	    $photo = new Photos();
		$photo ->addedby = $memid;
		$photo ->photo = trim($photos);
		$photo ->type = $org_type;
		$photo ->added_date = date('Y-m-d H:i:s');
		$photo ->photo_status = 1;
		$photo ->photo_diffid = $diffId;
		$photo ->comments_allow = $comments_allow;
		$photo ->album_id = $album_id;
		//$user ->created_by = $createdBy;
		$photo ->save();
		return $photo->photo_id;
		
	}
	public function getAlbumPhotosByAlbumId($memid,$album_id)
	{
		$query = new Doctrine_Query();
		$query->select('p.*')
		       ->from('Photos p')
			   ->where("p.album_id='".$album_id."'")
			   //->andWhere("p.addedby='".$memid."'")
			   ->andWhere("p.photo_status ='1'");
			   //echo $query->getSqlQuery();exit;
			   //->andWhere("e.send_type=1");
		$result = $query->execute(array(),Doctrine::HYDRATE_ARRAY);
		return $result;
	}
	public function getAlbumPhotosByPhotoId($photo_id)
	{
		$query = new Doctrine_Query();
		$query->select('p.*')
		       ->from('Photos p')
			   ->where("p.photo_id='".$photo_id."'")
			   //->andWhere("p.addedby='".$memid."'")
			   ->andWhere("p.photo_status ='1'");
			   //->andWhere("e.send_type=1");
		$result = $query->execute(array(),Doctrine::HYDRATE_ARRAY);
		return $result[0];
	}
	public function getPhoto($photo_id)
	{
		$query = new Doctrine_Query();
		$query->select('p.photo')
		       ->from('Photos p')
			   ->where("p.photo_id='".$photo_id."'");
			   //->andWhere("p.addedby='".$memid."'")
			   //->andWhere("e.send_type=1");
		$result = $query->execute(array(),Doctrine::HYDRATE_ARRAY);
		return $result[0];
	}
	public function addDescription($photo_id,$description)
	{
		 $query = new Doctrine_Query();
		$query->update('Photos p')
			  ->set('p.description',"'$description'")
			  ->where("p.photo_id='".$photo_id."'");
		  //echo $query->getSqlQuery();exit;
		return $query->execute();
	}
	public function addAlbum($user_id,$email,$data)
	{
		$AlbumCategory = new AlbumCategory();
		$AlbumCategory ->member_id = $user_id;
		$AlbumCategory ->title = $data['albumName'];
		$AlbumCategory ->added_by = $email;
		$AlbumCategory ->description = $data['description'];
		$AlbumCategory ->visitors_allow = $data['chkvisitor'];
		$AlbumCategory ->comments_allow = $data['chkcomment'];
		$AlbumCategory ->added_date = date('Y-m-d H:i:s');
		$AlbumCategory ->status = 1;
		//echo '<pre>';print_r($Groups);exit;
		$AlbumCategory ->save();
		return $AlbumCategory->album_id;
	}
	public function getAllPhotos($user_id,$currentPage,$resultsPerPage,$serValue='')
	{
		//echo $currentPage."   ,  ",$resultsPerPage;exit;
		$query = new Doctrine_Query();
		$query->select('a.*,r.user_id,r.is_owner,e.text as eventName,r.group_id,r.read_status,r.owner_id,r.status,u.first_name as first_name,g.name,d.photo as photo,m.status,m.owner_id')
		->addSelect('(SELECT COUNT(c.id) FROM EmComments c WHERE c.type_id=a.Photo_id AND c.status="Active") as cnt')
		       ->from('Photos a')
			   ->leftJoin('a.PhotoRelations r ON a.photo_id=r.photo_id')
			   ->leftJoin('r.EventsShared e ON r.event_id=e.event_id')
			   ->leftJoin('r.MyFavorites m ON m.type_id=r.photo_id AND m.type = "photos" AND m.owner_id='.$user_id)
			   ->leftJoin('r.Users u ON r.owner_id=u.user_id')
			   ->leftJoin('u.UserDetails d ON u.user_id=d.user_id')
			   ->leftJoin('r.Groups g ON g.group_id=r.group_id')
			   ->where("r.owner_id='".$user_id."' or r.user_id='".$user_id."'")
			   ->andWhere("r.status ='Active'")
			   ->orderBy("r.id desc");
				if($serValue!='')
				{
					//echo $serValue;exit;
					$query->andWhere("a.title LIKE '%".$serValue."%' OR a.description LIKE '%".$serValue."%'");
					
				} else {
					//echo 'oops';exit;
				}
				require_once('../database/models/dup_pager.php');
				$pager = new Pager($currentPage,$resultsPerPage);
				//echo '<pre>';print_r($pager);exit;
				$result = $pager->pagination($query);
				//echo '<pre>';print_r($result);exit;
				return $result;
	        
	}
	public function getPersonalPhotos($user_id,$currentPage,$resultsPerPage,$serValue='')
	{
		//echo $serValue;exit;
		$query = new Doctrine_Query();
		$query->select('a.*,r.user_id,r.is_owner,e.text as eventName,r.group_id,r.read_status,r.owner_id,r.status,u.first_name as first_name,g.name,d.photo as photo,m.status,m.owner_id')
		       ->addSelect('(SELECT COUNT(c.photo_diffid) FROM PhotoRelations c WHERE c.photo_diffid=a.photo_diffid and c.is_owner=1 and c.status="Active") as cnt')
			   ->addSelect('(SELECT COUNT(x.id) FROM EmComments x WHERE x.type_id=a.photo_id AND x.status="Active") as cnt1')
			   ->from('PhotoRelations r')
			   ->leftJoin('r.Photos a ON a.Photo_id=r.Photo_id')
			   ->leftJoin('r.EventsShared e ON r.event_id=e.event_id')
			   ->leftJoin('r.MyFavorites m ON m.type_id=r.Photo_id AND m.type = "photos" AND m.owner_id='.$user_id)
			   ->leftJoin('r.Users u ON r.owner_id=u.user_id')
			   ->leftJoin('u.UserDetails d ON u.user_id=d.user_id')
			   ->where("r.owner_id='".$user_id."'")
			   ->andWhere("r.status ='Active'")
   			   ->andWhere("r.group_id ='0'")
			  // ->andWhere("r.is_owner 	='1'")
			   ->orderBy("a.Photo_id desc")
			   ->groupBy('a.photo_diffid');
			    //echo $serValue;exit;
				if($serValue!='')
				{
					//echo $serValue;exit;
					$query->andWhere("a.description LIKE '%".$serValue."%'");
					
				} else {
					//echo 'oops';exit;
				}
			   //echo $query;exit;
			   //require_once('../database/models/Pager.php');
			   require_once('../database/models/dup_pager.php');
				$pager = new Pager($currentPage,$resultsPerPage);
				//echo $query->getSqlQuery();exit;
				$result = $pager->pagination($query);
				//echo '<pre>';print_r($result);exit;
				return $result;
	        
	}
	public function geSharetoMePhotos($user_id,$currentPage,$resultsPerPage,$serValue='')
	{
		//echo $currentPage."   ,  ",$resultsPerPage;exit;
		$query = new Doctrine_Query();
		$query->select('a.*,r.user_id,r.is_owner,e.text as eventName,r.group_id,r.read_status,r.owner_id,r.status,u.first_name as first_name,g.name,d.photo as photo,m.status,m.owner_id')
		->addSelect('(SELECT COUNT(c.id) FROM EmComments c WHERE c.type_id=a.photo_id AND c.status="Active") as cnt1')
		->addSelect('(SELECT COUNT(x.photo_diffid) FROM PhotoRelations x WHERE x.photo_diffid=r.photo_diffid AND x.user_id="'.$user_id.'") as cnt')
		       ->from('PhotoRelations r')
			   ->leftJoin('r.Photos a ON a.photo_id=r.photo_id')
			   ->leftJoin('r.EventsShared e ON r.event_id=e.event_id')
			   ->leftJoin('r.MyFavorites m ON m.type_id=r.photo_id AND m.type = "photos" AND m.owner_id='.$user_id)
			   ->leftJoin('r.Users u ON r.owner_id=u.user_id')
			   ->leftJoin('u.UserDetails d ON u.user_id=d.user_id')
			   ->leftJoin('r.Groups g ON g.group_id=r.group_id')
			   ->where("r.user_id=".$user_id)
			   ->andWhere("r.is_owner !='1'")
			   ->andWhere("r.status ='Active'")
			   ->orderBy("r.id desc")
			   ->groupBy('r.photo_diffid');
			   if($serValue!='')
				{
					//echo $serValue;exit;
					$query->andWhere("a.description LIKE '%".$serValue."%'");
					
				} else {
					//echo 'oops';exit;
				}
				//echo $query->getSqlQuery();exit;
				require_once('../database/models/dup_pager.php');
				$pager = new Pager($currentPage,$resultsPerPage);
				//echo '<pre>';print_r($pager);exit;
				$result = $pager->pagination($query,$serValue);
				//echo '<pre>';print_r($result);exit;
				return $result;
	        
	}
	public function getSharedPhotos($user_id,$currentPage,$resultsPerPage,$serValue='')
	{
		//echo $currentPage."   ,  ",$resultsPerPage;exit;
		$query = new Doctrine_Query();
		$query->select('a.*,r.user_id,r.is_owner,e.text as eventName,r.group_id,r.read_status,r.owner_id,r.status,u.first_name as first_name,g.name,d.photo as photo,m.status,m.owner_id')
		->addSelect('(SELECT COUNT(c.id) FROM EmComments c WHERE c.type_id=a.photo_id AND c.status="Active") as cnt1')
		->addSelect('(SELECT COUNT(c.photo_diffid) FROM Photos c WHERE c.photo_diffid=a.photo_diffid) as cnt1')
		       ->from('Photos a')
			   ->leftJoin('a.PhotoRelations r ON a.photo_id=r.photo_id')
			   ->leftJoin('r.EventsShared e ON r.event_id=e.event_id')
			   ->leftJoin('r.MyFavorites m ON m.type_id=r.album_id AND m.type = "photos" AND m.owner_id='.$user_id)
			   ->leftJoin('r.Users u ON r.owner_id=u.user_id')
			   ->leftJoin('u.UserDetails d ON u.user_id=d.user_id')
			   ->leftJoin('r.Groups g ON g.group_id=r.group_id')
			   ->where("r.owner_id='".$user_id."' or r.user_id='".$user_id."'")
			   ->andWhere("r.is_owner !='1'")
			   ->andWhere("r.status ='Active'")
			   ->orderBy("r.id desc")
			   ->groupBy('a.photo_diffid');
			   
				if($serValue!='')
				{
					//echo $serValue;exit;
					$query->andWhere("a.title LIKE '%".$serValue."%' OR a.description LIKE '%".$serValue."%'");
					
				} else {
					//echo 'oops';exit;
				}
			   //->groupBy('r.trigger_id')
			   //->orderBy("r.trigger_id desc");
			   //echo $query->getSqlQuery();exit;
				//require_once('../database/models/Pager.php');
				require_once('../database/models/dup_pager.php');
				$pager = new Pager($currentPage,$resultsPerPage);
				//echo '<pre>';print_r($pager);exit;
				$result = $pager->pagination($query);
				//echo '<pre>';print_r($result);exit;
				return $result;
	        
	}
	public function gettoSharePhotos($user_id,$currentPage,$resultsPerPage,$serValue='')
	{
		//echo $currentPage."   ,  ",$resultsPerPage;exit;
		$query = new Doctrine_Query();
		$query->select('a.*,r.user_id,r.is_owner,e.text as eventName,r.group_id,r.read_status,r.owner_id,r.read_status,r.status,u.first_name as first_name,g.name,d.photo as photo,m.status,m.owner_id')
		->addSelect('(SELECT COUNT(c.id) FROM EmComments c WHERE c.type_id=a.photo_id AND c.status="Active") as cnt1')
		->addSelect('(SELECT COUNT(x.photo_diffid) FROM Photos x WHERE x.photo_diffid=a.photo_diffid) as cnt')
		       ->from('Photos a')
			   ->leftJoin('a.PhotoRelations r ON a.photo_id=r.photo_id')
			   ->leftJoin('r.EventsShared e ON r.event_id=e.event_id')
			   ->leftJoin('r.MyFavorites m ON m.type_id=r.photo_id AND m.type = "photos" AND m.owner_id='.$user_id)
			   ->leftJoin('r.Users u ON r.owner_id=u.user_id')
			   ->leftJoin('u.UserDetails d ON u.user_id=d.user_id')
			   ->leftJoin('r.Groups g ON g.group_id=r.group_id')
			   ->where("r.owner_id=".$user_id)
			   ->andWhere("r.is_owner !='1'")
			   ->andWhere("r.status ='Active'")
			   ->orderBy("r.id desc")
			   ->groupBy('r.photo_diffid');
				if($serValue!='')
				{
					//echo $serValue;exit;
					$query->andWhere("a.title LIKE '%".$serValue."%' OR a.description LIKE '%".$serValue."%'");
					
				} else {
					//echo 'oops';exit;
				}
			  // echo $query->getSqlQuery();exit;
				require_once('../database/models/dup_pager.php');
				$pager = new Pager($currentPage,$resultsPerPage);
				//echo '<pre>';print_r($pager);exit;
				$result = $pager->pagination($query);
				//echo '<pre>';print_r($result);exit;
				return $result;
	        
	}
	
	/////////////album details by album id################################################################

public function getSharedPhotosByPhotoId($user_id,$photo_id)
	{
		//echo $user_id;exit;
		$query = new Doctrine_Query();
		$query->select('t.*,r.user_id,r.group_id,r.owner_id,u.first_name as first_name,g.name,m.status,m.owner_id,e.text as event_title')
		       ->from('Photos t')
			   ->leftJoin('t.PhotoRelations r ON t.photo_id=r.photo_id')
			   ->leftJoin('r.MyFavorites m ON m.type_id=r.photo_id AND m.type = "photos"')
			   ->leftJoin('r.Users u ON r.owner_id=u.user_id')
			   ->leftJoin('r.EventsShared e ON r.event_id=e.event_id')
			   ->leftJoin('u.UserDetails d ON u.user_id=d.user_id')
			   ->leftJoin('r.Groups g ON g.group_id=r.group_id')
			   ->where("r.owner_id='".$user_id."' or r.user_id='".$user_id."'")
			   ->andWhere("r.photo_id='".$photo_id."'")
			   ->andWhere("r.status ='Active'")
			   ->andWhere("r.is_owner !='1'");
			   $result = $query->execute(array(),Doctrine::HYDRATE_ARRAY);
				//echo '<pre>';print_r($result);exit;
				return $result[0];
	        
	}    
	public function getAllPhotosByPhotoId($user_id,$photo_id)
	{
		//echo $currentPage."   ,  ",$resultsPerPage;exit;
		$query = new Doctrine_Query();
		$query->select('a.*,r.user_id,r.is_owner,e.text as eventName,r.group_id,r.owner_id,r.read_status,r.status,u.first_name as first_name,g.name,m.status,m.owner_id')
		       ->from('Photos a')
			   ->leftJoin('a.PhotoRelations r ON a.photo_id=r.photo_id')
			   ->leftJoin('r.EventsShared e ON r.event_id=e.event_id')
			   ->leftJoin('r.MyFavorites m ON m.type_id=r.photo_id AND m.type = "photos" AND m.owner_id='.$user_id)
			   ->leftJoin('r.Users u ON r.owner_id=u.user_id')
			   ->leftJoin('u.UserDetails d ON u.user_id=d.user_id')
			   ->leftJoin('r.Groups g ON g.group_id=r.group_id')
			   ->where("r.owner_id='".$user_id."' or r.user_id='".$user_id."'")
			   ->andWhere("r.photo_id='".$photo_id."'")
			   ->andWhere("r.status ='Active'")
			   ->orderBy("r.id desc");
			   $result = $query->execute(array(),Doctrine::HYDRATE_ARRAY);
				//echo '<pre>';print_r($result);exit;
				return $result[0];
	        
	}
	public function getPersonalPhotosByPhotoId($user_id,$photo_diffid,$currentPage,$resultsPerPage)
	{
		//echo $serValue;exit;
		$query = new Doctrine_Query();
		$query->select('a.*,r.user_id,r.is_owner,r.id as relation_id,e.event_id as event_id,e.text as eventName,r.group_id,r.owner_id,r.read_status,r.status,u.first_name as first_name,g.name,m.status,m.owner_id')
		       ->from('Photos a')
			   ->leftJoin('a.PhotoRelations r ON a.photo_id=r.photo_id')
			   ->leftJoin('r.EventsShared e ON r.event_id=e.event_id')
			   ->leftJoin('r.MyFavorites m ON m.type_id=r.photo_id AND m.type = "photos" AND m.owner_id='.$user_id)
			   ->leftJoin('r.Users u ON r.owner_id=u.user_id')
			   ->leftJoin('u.UserDetails d ON u.user_id=d.user_id')
			   ->where("r.owner_id='".$user_id."'")
			   ->andWhere("r.photo_diffid='".$photo_diffid."'")
			   ->andWhere("r.status ='Active'")
   			   //->andWhere("r.group_id ='0'")
			   ->orderBy("a.photo_id desc");
			    //echo $serValue;exit;
				//echo $query->getSqlQuery();exit;
				require_once('../database/models/Pager.php');
			$pager = new Pager($currentPage,$resultsPerPage);
			
			$result = $pager->pagination($query);
			//echo '<pre>';print_r($result);exit;
			return $result;
	        
	}
	public function gettoSharePhotosByPhotoId($user_id,$photo_diffid)
	{
		//echo $currentPage."   ,  ",$resultsPerPage;exit;
		$query = new Doctrine_Query();
		$query->select('a.*,r.user_id,r.is_owner,e.text as eventName,r.group_id,r.owner_id,r.read_status,r.status,u.first_name as first_name,g.name,m.status,m.owner_id')
			   ->from('Photos a')
			   ->leftJoin('a.PhotoRelations r ON a.photo_id=r.photo_id')
			   ->leftJoin('r.EventsShared e ON r.event_id=e.event_id')
			   ->leftJoin('r.MyFavorites m ON m.type_id=r.photo_id AND m.type = "photos" AND m.owner_id='.$user_id)
			   ->leftJoin('r.Users u ON r.owner_id=u.user_id')
			   ->leftJoin('u.UserDetails d ON u.user_id=d.user_id')
			   ->leftJoin('r.Groups g ON g.group_id=r.group_id')
			   ->where("r.owner_id=".$user_id)
			   ->andWhere("r.photo_diffid='".$photo_diffid."'")
			   ->andWhere("r.is_owner !='1'")
			   ->andWhere("r.status ='Active'")
			   ->orderBy("r.id desc");
				$result = $query->execute(array(),Doctrine::HYDRATE_ARRAY);
				//echo '<pre>';print_r($result);exit;
				return $result;
	        
	}
		public function geSharetoMePhotosByPhotoId($user_id,$photo_diffid,$currentPage,$resultsPerPage)
	{
		//echo $currentPage."   ,  ",$resultsPerPage;exit;
		$query = new Doctrine_Query();
		$query->select('a.*,r.user_id,r.is_owner,e.text as eventName,r.group_id,r.owner_id,r.read_status,r.status,u.first_name as first_name,g.name,m.status,m.owner_id')
		       ->from('Photos a')
			   ->leftJoin('a.PhotoRelations r ON a.photo_id=r.photo_id')
			   ->leftJoin('r.EventsShared e ON r.event_id=e.event_id')
			   ->leftJoin('r.MyFavorites m ON m.type_id=r.photo_id AND m.type = "photos" AND m.owner_id='.$user_id)
			   ->leftJoin('r.Users u ON r.owner_id=u.user_id')
			   ->leftJoin('r.Groups g ON g.group_id=r.group_id')
			   ->where("r.user_id=".$user_id)
			   ->andWhere("r.is_owner !='1'")
			   ->andWhere("r.photo_diffid='".$photo_diffid."'")
			   ->andWhere("r.status ='Active'")
			   ->orderBy("r.id desc");
				//echo $query->getSqlQuery();exit;
				require_once('../database/models/Pager.php');
			$pager = new Pager($currentPage,$resultsPerPage);
			
			$result = $pager->pagination($query);
			//echo '<pre>';print_r($result);exit;
			return $result;
        
	}
	////// end of the get albums by album id ################################################
	 
/// doctrine queries for photos view largeee ################################################
	public function getPersonalPhotosByPhotoDiffid($user_id,$photo_diffid)
	{
		//echo $serValue;exit;
		$query = new Doctrine_Query();
		$query->select('a.*,r.user_id,r.is_owner,r.id as relation_id,e.event_id as event_id,e.text as eventName,r.group_id,r.owner_id,r.read_status,r.status,u.first_name as first_name,g.name,m.status,m.owner_id,d.photo as user_photo')
		       ->from('Photos a')
			   ->leftJoin('a.PhotoRelations r ON a.photo_id=r.photo_id')
			   ->leftJoin('r.EventsShared e ON r.event_id=e.event_id')
			   ->leftJoin('r.MyFavorites m ON m.type_id=r.photo_id AND m.type = "photos" AND m.owner_id='.$user_id)
			   ->leftJoin('r.Users u ON r.owner_id=u.user_id')
			   ->leftJoin('u.UserDetails d ON u.user_id=d.user_id')
			   ->where("r.owner_id='".$user_id."'")
			   ->andWhere("r.photo_diffid='".$photo_diffid."'")
			   ->andWhere("r.status ='Active'")
   			   //->andWhere("r.group_id ='0'")
			   ->orderBy("a.photo_id desc");
			    //echo $serValue;exit;
				//echo $query->getSqlQuery();exit;
				$result = $query->execute(array(),Doctrine::HYDRATE_ARRAY);
				//echo '<pre>';print_r($result);exit;
				return $result;
	        
	}
	public function geSharetoMePhotosByPhotoDiffid($user_id,$photo_diffid)
	{
		//echo $currentPage."   ,  ",$resultsPerPage;exit;
		$query = new Doctrine_Query();
		$query->select('a.*,r.user_id,r.is_owner,e.text as eventName,r.group_id,r.owner_id,r.read_status,r.status,u.first_name as first_name,g.name,m.status,m.owner_id,d.photo as user_photo')
		       ->from('Photos a')
			   ->leftJoin('a.PhotoRelations r ON a.photo_id=r.photo_id')
			   ->leftJoin('r.EventsShared e ON r.event_id=e.event_id')
			   ->leftJoin('r.MyFavorites m ON m.type_id=r.photo_id AND m.type = "photos" AND m.owner_id='.$user_id)
			   ->leftJoin('r.Users u ON r.owner_id=u.user_id')
			   ->leftJoin('r.Groups g ON g.group_id=r.group_id')
			   ->leftJoin('u.UserDetails d ON u.user_id=d.user_id')
			   ->where("r.user_id=".$user_id)
			   ->andWhere("r.is_owner !='1'")
			   ->andWhere("r.photo_diffid='".$photo_diffid."'")
			   ->andWhere("r.status ='Active'")
			   ->orderBy("r.id desc");
				//echo $query->getSqlQuery();exit;
				$result = $query->execute(array(),Doctrine::HYDRATE_ARRAY);
				//echo '<pre>';print_r($result);exit;
				return $result;
        
	}
	public function geSharetoMePhotosActivity($user_id,$currentPage,$resultsPerPage,$serValue='')
	{
		//echo $currentPage."   ,  ",$resultsPerPage;exit;
		$query = new Doctrine_Query();
		$query->select('a.*,r.user_id,r.is_owner,e.text as eventName,r.group_id,r.read_status,r.owner_id,r.status,u.first_name as first_name,g.name,d.photo as photo,m.status,m.owner_id')
		->addSelect('(SELECT COUNT(c.id) FROM EmComments c WHERE c.type_id=a.photo_id AND c.status="Active") as cnt1')
		->addSelect('(SELECT COUNT(x.photo_diffid) FROM PhotoRelations x WHERE x.photo_diffid=r.photo_diffid AND x.user_id="'.$user_id.'") as cnt')
		       ->from('PhotoRelations r')
			   ->leftJoin('r.Photos a ON a.photo_id=r.photo_id')
			   ->leftJoin('r.EventsShared e ON r.event_id=e.event_id')
			   ->leftJoin('r.MyFavorites m ON m.type_id=r.photo_id AND m.type = "photos" AND m.owner_id='.$user_id)
			   ->leftJoin('r.Users u ON r.owner_id=u.user_id')
			   ->leftJoin('u.UserDetails d ON u.user_id=d.user_id')
			   ->leftJoin('r.Groups g ON g.group_id=r.group_id')
			   ->where("r.user_id=".$user_id)
			   ->andWhere("r.is_owner !='1'")
			   ->andWhere("r.status ='Active'")
			   ->orderBy("r.id desc");
			   //->groupBy('r.photo_diffid');
				//echo $query->getSqlQuery();exit;
				require_once('../database/models/dup_pager.php');
				$pager = new Pager($currentPage,$resultsPerPage);
				//echo '<pre>';print_r($pager);exit;
				$result = $pager->pagination($query,$serValue);
				//echo '<pre>';print_r($result);exit;
				return $result;
	        
	}
	public function getPersonalPhotosActivity($user_id,$currentPage,$resultsPerPage,$serValue='')
	{
		//echo $serValue;exit;
		$query = new Doctrine_Query();
		$query->select('a.*,r.user_id,r.is_owner,e.text as eventName,r.group_id,r.read_status,r.owner_id,r.status,u.first_name as first_name,g.name,d.photo as photo,m.status,m.owner_id')
		       ->addSelect('(SELECT COUNT(c.photo_diffid) FROM PhotoRelations c WHERE c.photo_diffid=a.photo_diffid and c.is_owner=1 and c.status="Active") as cnt')
			   ->addSelect('(SELECT COUNT(x.id) FROM EmComments x WHERE x.type_id=a.photo_id AND x.status="Active") as cnt1')
			   ->from('PhotoRelations r')
			   ->leftJoin('r.Photos a ON a.Photo_id=r.Photo_id')
			   ->leftJoin('r.EventsShared e ON r.event_id=e.event_id')
			   ->leftJoin('r.MyFavorites m ON m.type_id=r.Photo_id AND m.type = "photos" AND m.owner_id='.$user_id)
			   ->leftJoin('r.Users u ON r.owner_id=u.user_id')
			   ->leftJoin('u.UserDetails d ON u.user_id=d.user_id')
			   ->where("r.owner_id='".$user_id."'")
			   ->andWhere("r.status ='Active'")
   			   ->andWhere("r.group_id ='0'")
			   ->andWhere("r.is_owner 	='1'")
			   ->orderBy("a.Photo_id desc");
			   //->groupBy('a.photo_diffid');
			    //echo $serValue;exit;
				if($serValue!='')
				{
					//echo $serValue;exit;
					$query->andWhere("a.title LIKE '%".$serValue."%' OR a.description LIKE '%".$serValue."%'");
					
				} else {
					//echo 'oops';exit;
				}
			   //echo $query;exit;
			   //require_once('../database/models/Pager.php');
			   require_once('../database/models/dup_pager.php');
				$pager = new Pager($currentPage,$resultsPerPage);
				//echo $query->getSqlQuery();exit;
				$result = $pager->pagination($query);
				//echo '<pre>';print_r($result);exit;
				return $result;
	        
	}

}